package com.itown.expo.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.springframework.web.servlet.ModelAndView;

import webframe.common.helper.ControllerHelper;
import webframe.common.helper.FormatTransformHelper;

import com.itown.expo.controller.base.MyBaseCommandController;
import com.itown.expo.model.NormalGoodsDecl;

public class NormalDeclSearchController extends MyBaseCommandController {
	private static Order[] orders = new Order[] { Order.desc("declDate") };

	@Override
	protected ModelAndView handleInner(HttpServletRequest request,
			HttpServletResponse response, Object command) {
		NormalGoodsDecl cdecl = (NormalGoodsDecl) command;

		DetachedCriteria criteria = DetachedCriteria
				.forClass(NormalGoodsDecl.class);
		ControllerHelper.addEqualRestrictions(criteria, "id", cdecl.getId());
		ControllerHelper.addLikeRestrictions(criteria, "declNo", cdecl
				.getDeclNo());
		ControllerHelper.addEqualRestrictions(criteria, "backupCode", cdecl
				.getBackupCode());
		ControllerHelper.addEqualRestrictions(criteria, "colligateResult",
				cdecl.getColligateResult());
		// 报检日期范围
		ControllerHelper.addBetweenRestrictions(criteria, "declDate",
				FormatTransformHelper.string2Date(cdecl.getTradeModeCode()),
				FormatTransformHelper.string2Date(cdecl.getTradeModeName()));

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("appPrefix", getAppPrefix());
		map.put("page", ControllerHelper.queryPagination(request, orders,
				criteria));
		map.put("cdecl", cdecl);
		return new ModelAndView("NormalDeclList.jsp", "map", map);
	}

}
